def process_file_list(file_list_path):
    # 定义要搜索的关键字（包含双引号）
    keywords = ['"Facebox"', '"Pedestrianbox"', '"NonMotorVehiclesbbox"']
    # 关键字对应的输出名称（不带引号）
    output_names = ['Facebox', 'Pedestrianbox', 'NonMotorVehiclesbbox']
    
    # 读取文件列表
    with open(file_list_path, 'r') as list_file:
        files = [line.strip() for line in list_file.readlines() if line.strip()]
    
    # 处理结果写入输出文件
    with open('result.txt', 'w') as result_file:
        for filename in files:
            try:
                # 读取当前文件内容
                with open(filename, 'r') as current_file:
                    content = current_file.read()
                
                # 检查每个关键字是否在文件中出现
                found_keywords = []
                for kw, name in zip(keywords, output_names):
                    if kw in content:
                        found_keywords.append(name)
                
                # 如果有找到关键字，按格式输出
                if found_keywords:
                    result_line = f"{filename}|{'|'.join(found_keywords)}\n"
                    result_file.write(result_line)
            
            except FileNotFoundError:
                print(f"警告: 文件 {filename} 不存在，跳过处理")
            except Exception as e:
                print(f"处理文件 {filename} 时出错: {str(e)}")

# 示例调用
if __name__ == "__main__":
    process_file_list("file_list.txt")  # 替换为你的文件列表路径

